#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128 bi;
const int N=(1<<20)+3;
ll n,SZ,qa[N],num[N];
bool vis[N]; 
map<ll,ll>mp;
#define ls (p<<1)
#define rs (p<<1|1)
#define mi ((l+r)>>1)
#define lson ls,l,mi
#define rson rs,mi+1,r
struct SGT
{
	ll sz[N],sum[N];
	void Up(int p){sz[p]=sz[ls]+sz[rs];sum[p]=sum[ls]+sum[rs];}
	void Mdf(int k,ll d,int p=1,int l=1,int r=n)
	{
		if(l==r){sum[p]=d;sz[p]=d>0;return;}
		k<=mi?Mdf(k,d,lson):Mdf(k,d,rson);Up(p);
	}
	ll Kthmin(int k,int p=1,int l=1,int r=n)
	{
		if(!k)return 0;
		ll s=0;
		while(l<r)
		{
			if(k<=sz[ls])r=mi,p=p<<1;
			else k-=sz[ls],s+=sum[ls],l=mi+1,p=p<<1|1;
		}
		return s+sum[p];
	}
	ll Kthmax(int k,int p=1,int l=1,int r=n)
	{
		if(!k)return 0;
		ll s=0;
		while(l<r)
		{
			if(k<=sz[rs])l=mi+1,p=p<<1|1;
			else k-=sz[rs],s+=sum[rs],r=mi,p=p<<1;
		}
		return s+sum[p];
	}
	ll Valmin(int k,int p=1,int l=1,int r=n)
	{
		if(l==r)return l;
		if(k<=sz[ls])return Valmin(k,lson);
		return Valmin(k-sz[ls],rson);
	}
	ll Valmax(int k,int p=1,int l=1,int r=n)
	{
		if(l==r)return l;
		if(k<=sz[rs])return Valmax(k,rson);
		return Valmax(k-sz[rs],lson);
	}
	bi Sum(int L,int R,int p=1,int l=1,int r=n)
	{
		if(L>R)return 0;
		if(L<=l&&r<=R)return sum[p];
		if(R<=mi)return Sum(L,R,lson);
		if(L>mi)return Sum(L,R,rson);
		return Sum(L,R,lson)+Sum(L,R,rson);
	}
}T;
struct SGT2
{
	bi tr[N],res[N],tag[N],len[N];
	void Up(int p){tr[p]=tr[ls]+tr[rs];len[p]=len[ls]+len[rs];}
	void Add(int p,ll d){tr[p]+=d*len[p];tag[p]+=d;}
	void Down(int p){Add(ls,tag[p]);Add(rs,tag[p]);tag[p]=0;}
	void Mdf(int k,int op,int p=1,int l=1,int r=n)
	{
		if(l==r){len[p]=op;tr[p]=op*tag[p];return;}
		Down(p);k<=mi?Mdf(k,op,lson):Mdf(k,op,rson);Up(p);
	}
	void Upd(int L,int R,ll d,int p=1,int l=1,int r=n)
	{
		if(L<=l&&r<=R)return Add(p,d);
		Down(p);
		if(L<=mi)Upd(L,R,d,lson);
		if(R>mi)Upd(L,R,d,rson);
		Up(p); 
	}
	bi Ask(int L,int R,int p=1,int l=1,int r=n)
	{
		if(L>R)return 0;
		if(L<=l&&r<=R)return tr[p];
		Down(p);
		if(R<=mi)return Ask(L,R,lson);
		if(L>mi)return Ask(L,R,rson);
		return Ask(L,R,lson)+Ask(L,R,rson);
	}
}T2,T3;
ll Solve(ll x)
{
	ll id=mp[x];
	if(vis[id])
	{
		T.Mdf(id,0),vis[id]=0,SZ--;
		T2.Upd(id,n,-x),T3.Upd(1,id,-x);T2.Mdf(id,0),T3.Mdf(id,0);
	}
	else
	{
		T.Mdf(id,x),vis[id]=1,SZ++;
		T2.Mdf(id,1),T3.Mdf(id,1);T2.Upd(id,n,x),T3.Upd(1,id,x);
	}
	if(SZ<=1)return 0;
	ll midp=(SZ+1)/2;
	ll l=1,r=midp,s1=0;
	while(l<=r)T.Kthmin(mi)>=T.Kthmax(mi-1)?(s1=mi,l=mi+1):r=mi-1;
	l=midp+1,r=n;ll s2=0;
	while(l<=r)T.Kthmin(mi)>=T.Kthmax(mi-1)?(s2=mi,r=mi-1):l=mi+1;
	bi sum=T.sum[1];
	bi v1=T2.Ask(1,T.Valmin(s1))-(s1==1?0:T3.Ask(T.Valmax(s1-1),n));
	bi v2=T2.Ask(T.Valmin(s2),n)-T3.Ask(T.Valmin(1)+1,T.Valmax(s2-1));
	return sum-v1-v2;
}
int main()
{
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int tt;cin>>tt;
	for(int i=1;i<=tt;i++)cin>>qa[i],mp[qa[i]]=1;
	for(auto &p:mp)p.second=++n,num[n]=p.first;
	for(int i=1;i<=tt;i++)cout<<Solve(qa[i])<<"\n";
}
